import apiService from '../../services/api';
Page({
  data: {
    detail: null,
    detail1:null,
    detail3:null,
    detail2:[],
    error: null
  },
  async onLoad(options) {
    const { id, table } = options;
    // 拼接SQL
    const sql = `SELECT * FROM novels WHERE id = ${id}`;
    const sql1 = `SELECT * FROM comments WHERE comment_id = ${id}`;
    const sql3 = `SELECT * FROM replies WHERE reply_id = ${id}`;
    const sql2 = `SELECT * FROM novel_chapters WHERE novel_id = ${id}`;
    try {
      const result = await apiService.executeSql(sql);
      if (result.success && result.data.length > 0) {
        this.setData({
          detail: result.data[0]
        });
      } else {
        this.setData({
          error: '未找到数据'
        });
      }
      console.log(result)
    } catch (e) {
      this.setData({
        error: e.message || '查询失败'
      });
    }

    try {
      const result = await apiService.executeSql(sql1);
      if (result.success && result.data.length > 0) {
        this.setData({
          detail1: result.data[0]
        });
      } else {
        this.setData({
          error: '未找到数据'
        });
      }
      console.log(result)
    } catch (e) {
      this.setData({
        error: e.message || '查询失败'
      });
    }

    try {
      const result = await apiService.executeSql(sql2);
      if (result.success && result.data.length > 0) {
        this.setData({
          detail2: result.data
        })
        console.log(result)
      } else {
        this.setData({
          error: '未找到数据'
        });
      }
    } catch (e) {
      this.setData({
        error: e.message || '查询失败'
      });
    }

    try {
      const result = await apiService.executeSql(sql3);
      if (result.success && result.data.length > 0) {
        this.setData({
          detail3: result.data[0]
        })
        console.log(result)
      } else {
        this.setData({
          error: '未找到数据'
        });
      }
    } catch (e) {
      this.setData({
        error: e.message || '查询失败'
      });
    }
  },


  
  
});